using System;
using System.Collections.Generic;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services;

namespace JlPay.Sdk.Models
{
    /// <summary>
    /// 基础请求类
    /// </summary>
    public class OrgBaseRequest : IRawMapGetter, ISensitiveFieldsProvider
    {
        /// <summary>
        /// 机构号
        /// </summary>
        public string OrgNo { get; set; } = string.Empty;
        
        /// <summary>
        /// 商户号
        /// </summary>
        public string MerchNo { get; set; } = string.Empty;
        
        /// <summary>
        /// 敏感字段列表
        /// </summary>
        private readonly List<string> _sensitiveFields = new();
        
        /// <summary>
        /// 原始数据映射
        /// </summary>
        private Dictionary<string, object>? _rawMap;

        /// <summary>
        /// 添加敏感字段
        /// </summary>
        public void AddSensitiveField(string fieldPath)
        {
            if (!_sensitiveFields.Contains(fieldPath))
            {
                _sensitiveFields.Add(fieldPath);
            }
        }

        /// <summary>
        /// 获取敏感字段列表
        /// </summary>
        public List<string> GetSensitiveFields() => new(_sensitiveFields);

        /// <summary>
        /// 设置原始数据映射
        /// </summary>
        public void SetRawRequestMap(Dictionary<string, object> rawMap)
        {
            _rawMap = rawMap;
        }

        /// <summary>
        /// 获取原始数据映射
        /// </summary>
        public (Dictionary<string, object> rawMap, bool exists) GetRawMap()
        {
            if (_rawMap == null || _rawMap.Count == 0)
            {
                return (new Dictionary<string, object>(), false);
            }
            return (_rawMap, true);
        }
    }
} 